package com.wltjack.springboot.controller;

import com.google.gson.Gson;
import com.wltjack.springboot.common.MyHealthIndicatorSecond;
import com.wltjack.springboot.common.SpringUtils;
import com.wltjack.springboot.vo.MemberVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/membertest")
public class HelloController {
	
	@Autowired
	private Gson gson;

	@ApiOperation(value="打印文本内容测试", notes="测试")
	@RequestMapping(value = "/hello", method = RequestMethod.GET)
	public String hello() {
		MyHealthIndicatorSecond myHealthIndicatorSecond = (MyHealthIndicatorSecond) SpringUtils.getApplicationContext().getBean("myHealthIndicatorSecond");
		System.out.println(myHealthIndicatorSecond);
		return "test spring boot";
	}
	
	@ApiOperation(value="获取会员列表", notes="获取会员列表")
	@RequestMapping(value = "/getMemberList", method = RequestMethod.POST)
	public List<MemberVO> getMemberList(){
		List<MemberVO> list = new ArrayList<MemberVO>();
		MemberVO memberVO = new MemberVO();
		memberVO.setMemberId("123456");
		memberVO.setMemberName("小白");
		memberVO.setMemo("测试");
		list.add(memberVO);
		memberVO = new MemberVO();
		memberVO.setMemberId("123457");
		memberVO.setMemberName("小白2");
		memberVO.setMemo("测试2");
		list.add(memberVO);
		memberVO = new MemberVO();
		memberVO.setMemberId("123459");
		memberVO.setMemberName("小白3");
		memberVO.setMemo("测试3");
		list.add(memberVO);
		return list;
	}
	
	@ApiOperation(value="获取会员详细信息", notes="根据url中的id来获取会员详细信息")
	@ApiImplicitParam(name="id",value="会员id",required=true,dataType="String")
	@RequestMapping(value = "/getMemberDetail/{id}", method = RequestMethod.GET)
	public String getMemberDetail(@PathVariable String id) {
		MemberVO memberVO = new MemberVO();
		memberVO.setMemberId(id);
		memberVO.setMemberName("小白");
		memberVO.setMemo("测试");
		return gson.toJson(memberVO);
	}
}
